import { MalfunctionModel, MalfunctionTypeModel } from '../model/malfunction';
import { NotFound } from 'lin-mizar';
class MalfunctionDao {
  async getMalfunction (id) {
    const info = await MalfunctionModel.findByPk(id);
    if (!info) {
      throw new NotFound({
        code: 10241
      });
    }
    return info;
  }

  async getMalfunctionType () {
    const list = await MalfunctionTypeModel.findAll();

    return list;
  }

  async createMalfunctionType (v) {
    const info = await MalfunctionTypeModel.create({
      name: v.get('body.name'),
      type: v.get('body.type')
    });
    return info;
  }
}

export { MalfunctionDao };
